package io.commchina.smart.parking.biz.modules.strategy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.commchina.platform.framework.biz.BizTemplate;
import io.commchina.platform.framework.sip.utils.PageUtils;
import io.commchina.platform.framework.sip.utils.Query;
import io.commchina.smart.parking.biz.modules.strategy.CarParkingStrategyService;
import io.commchina.smart.parking.dao.modules.strategy.CarParkingStrategyDao;
import io.commchina.smart.parking.dao.modules.strategy.entity.CarParkingStrategyEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * 代码千万行，注释第一行
 * 注释不规范，同事泪两行
 * <p>
 *
 * @author ChenMiLi
 * @version 1.0
 * @date 2021/9/28 14:04
 */

/**
 * 车位策略
 */
@Service
@Slf4j
public class CarParkingStrategyServiceImpl extends ServiceImpl<CarParkingStrategyDao, CarParkingStrategyEntity> implements CarParkingStrategyService {
    @Autowired
    private CarParkingStrategyDao carParkingStrategyDao;

    /**
     * 查询车位策略列表
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CarParkingStrategyEntity> page = this.page(
                new Query<CarParkingStrategyEntity>().getPage(params)
        );
        return new PageUtils(page);

    }

    /**
     * 查询指定车位策略
     *
     * @param strategyId
     * @return
     */
    @Override
    public CarParkingStrategyEntity getByTypeId(Integer strategyId) {
        QueryWrapper<CarParkingStrategyEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("strategy_id", strategyId);
        CarParkingStrategyEntity carParkingStrategy = carParkingStrategyDao.selectOne(queryWrapper);
        return carParkingStrategy;
    }

    /**
     * 新增车位策略
     *
     * @param carParkingStrategyEntity
     */
    @Override
    public void addStrategy(CarParkingStrategyEntity carParkingStrategyEntity) {
        carParkingStrategyDao.insert(carParkingStrategyEntity);
    }

    /**
     * 删除指定车位策略
     *
     * @param strategyId
     */
    @Override
    public void deleteStrategy(Integer strategyId) {
        QueryWrapper<CarParkingStrategyEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("strategy_id", strategyId);
        carParkingStrategyDao.delete(queryWrapper);
    }

    /**
     * 更新车位策略
     *
     * @param carParkingStrategyEntity
     */
    @Override
    public void updateStrategy(CarParkingStrategyEntity carParkingStrategyEntity) {
        QueryWrapper<CarParkingStrategyEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("strategy_id", carParkingStrategyEntity.getStrategyId());
        carParkingStrategyDao.update(carParkingStrategyEntity, queryWrapper);
    }


}
